#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

typedef long long ll;
typedef double db;
typedef vector < int > vec;
typedef pair < int , int > pii;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 1e5 + 10;
const int M = 3e5 + 10;

int h[N],cnt,n,m,lim[N],ans[N],Q;
struct edge { int u, v, x, y, nxt; } e[M];
void link(int x, int y, int st, int ed) { e[++cnt] = (edge) { x, y, st, ed, h[x] }; h[x] = cnt; }
int id[N],pot1[N],pot2[N];
int f[N];
bool vis[N];

void solve(int xl, int xr,int l,int r) {
	if(l > r || xl > xr) return;
//	cerr << xl << " " << xr << " " << l << " " << r << endl;
	int mid = l + r >> 1;
	rep(i, 1, n) f[i] = 2e9,vis[i] = false;
	f[1] = mid; priority_queue < pii, vector < pii >, greater < pii >> q; q.push({ mid,1 });
	while(q.size()) {
		int x = q.top().se; q.pop(); if(vis[x]) continue; vis[x] = true;
		for(int i = h[x],y; i; i = e[i].nxt)
			if(f[x] <= e[i].x) {
				y = e[i].v; if(f[y] > e[i].y) f[y] = e[i].y,q.push({ f[y],y });
			} else break;
	}
	int top1 = 0,top2 = 0;
	rep(i, xl, xr) if(f[n] <= lim[id[i]]) pot1[++top1] = id[i]; else pot2[++top2] = id[i];
	rep(i, 1, top1) ans[pot1[i]] = max(mid,ans[pot1[i]]);
	rep(i, xl, xl + top1 - 1) id[i] = pot1[i - xl + 1];
	rep(i, xl + top1, xr) id[i] = pot2[i - (xl + top1) + 1];
	solve(xl, xl + top1 - 1, mid + 1, r);
	solve(xl + top1, xr, l, mid - 1);
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("04-10.in","r",stdin); freopen("output.txt","w",stdout);
#endif
	n = in,m = in;
	rep(i, 1, m) {
		int u = in,v = in,x = in,y = in;
		e[i] = (edge) { u, v, x, y };
	}
	sort(e + 1, e + m + 1, [](edge a,edge b) { return a.x < b.x; });
	rep(i, 1, m) link(e[i].u, e[i].v, e[i].x, e[i].y);
	Q = in; rep(i, 1, Q) lim[i] = in,ans[i] = -1;
	rep(i, 1, Q) id[i] = i;
	solve(1, Q, 0, 86500000);
	rep(i, 1, Q) printf("%d\n",ans[i]);
	return 0;
}
